export default {
    // 真正实现代码模块化，作用域都被隔离了
    namespaced: true,
    state: {
        count: 0,
    },
    mutations: {
        // loginSuccess(state, payload) {
        //     state.isLogin = true;
        //     state.token = payload.token;
        //     state.user = payload.user;
        // },
        increate(state, num = 1) {
            state.count += num;
        },
    },
    actions: {
        async increateAsync(ctx, num = 5) {
            // 登录
            // const res = await new Promise((resolve) => {
            //     // 写异步操作
            //     http.post('/login').then((res) => {
            //         resolve(res);
            //     });
            // });
            // 登录成功，保存登录态
            // ctx.commit('loginSuccess', res);

            // 模拟异步操作，这里没意义
            await new Promise((resolve) => {
                setTimeout(() => {
                    resolve(true);
                }, 2000);
            });
            ctx.commit('increate', num);
        },
    },
    getters: {
        sum(state) {
            return `共加了多少 ${state.count}`;
        },
    },
};
